﻿<UserControl x:Class="VmroleAuthor.Views.ScriptApplicationView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignWidth="900">
    <UserControl.Resources>
        <Style x:Key="TextBlockStyle" TargetType="{x:Type TextBlock}">
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="true">
                    <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}"/>
                </Trigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>
    <Grid VerticalAlignment="Top" ShowGridLines="False">
        <Grid.RowDefinitions >
            <RowDefinition Height="6" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition MinHeight="30" />
            <RowDefinition Height="Auto" />            
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition MinHeight="30" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="6"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="6"/>
        </Grid.ColumnDefinitions>

        <!-- Application Payload Id-->
        <Label Grid.Row="1" Grid.Column="0" >Application Payload</Label>
        <ContentControl Grid.Row="1" Grid.Column="2" Content="{Binding Path= ScriptAppPackage}" />

        <!--DeploymentName-->
        <Label  Grid.Row="2" Grid.Column="0" >DeploymentName</Label>
        <ContentControl Grid.Row="2" Grid.Column="2" Content="{Binding Path=DeploymentName}" />

        <!-- AlwaysReboot -->
        <Label Grid.Row="3" Grid.Column="0" >Always Reboot</Label>
        <ContentControl Grid.Row="3" Grid.Column="2" Content="{Binding Path=AlwaysReboot}" />
        
        <!--ErrorPolicy -->
        <Label  Grid.Row="4" Grid.Column="0" >ErrorPolicy</Label>
        <ContentControl Grid.Row="4" Grid.Column="2" Content="{Binding Path=ErrorPolicy}" />

        <!--Executable -->
        <Label  Grid.Row="5" Grid.Column="0" >Executable</Label>
        <ContentControl Grid.Row="5" Grid.Column="2" Content="{Binding Path=Executable}" />

        <!--Parameters -->
        <Label  Grid.Row="6" Grid.Column="0" >Parameters</Label>
        <ContentControl Grid.Row="6" Grid.Column="2" Content="{Binding Path=Parameters}" />

        <!--ExitCodeRegex  -->
        <Label  Grid.Row="7" Grid.Column="0" >ExitCodeRegex</Label>
        <ContentControl Grid.Row="7" Grid.Column="2" Content="{Binding Path=ExitCodeRegex}" />

        <!--MaxOutputSize  -->
        <Label  Grid.Row="8" Grid.Column="0" >MaxOutputSize</Label>
        <ContentControl Grid.Row="8" Grid.Column="2" Content="{Binding Path=MaxOutputSize}" />

        <!--RebootExitCodeRegex  -->
        <Label  Grid.Row="9" Grid.Column="0" >RebootExitCodeRegex</Label>
        <ContentControl Grid.Row="9" Grid.Column="2" Content="{Binding Path=RebootExitCodeRegex}" />

        <!-- RestartOnExitCodeReboot -->
        <Label  Grid.Row="10" Grid.Column="0" >RestartOnExitCodeReboot</Label>
        <ContentControl VerticalAlignment="Center" Grid.Row="10" Grid.Column="2" Content="{Binding Path=RestartOnExitCodeReboot}" />

        <!--ScriptBlock  -->
        <Label  Grid.Row="11" Grid.Column="0" >ScriptBlock</Label>
        <TextBox x:Name="ScriptBlock" VerticalAlignment="Center" Grid.Row="11" Grid.Column="2" Text="{Binding ScriptBlock.PropertyValue, ValidatesOnDataErrors=True}" Validation.ErrorTemplate="{x:Null}"  AcceptsReturn="True" />
        <ContentPresenter Grid.Row="12" Grid.Column ="2" Content="{Binding ElementName=ScriptBlock, Path=(Validation.Errors).CurrentItem}" />

        <!--ScriptCredential  -->
        <Label  Grid.Row="13" Grid.Column="0" >ScriptCredential</Label>
        <ContentControl Grid.Row="13" Grid.Column="2" Content="{Binding Path=ScriptCredential}" />

        <!--StandardErrorPath  -->
        <Label  Grid.Row="14" Grid.Column="0" >StandardErrorPath</Label>
        <ContentControl Grid.Row="14" Grid.Column="2" Content="{Binding Path=StandardErrorPath}" />

        <!--StandardErrorRegex  -->
        <Label  Grid.Row="15" Grid.Column="0" >StandardErrorRegex</Label>
        <ContentControl Grid.Row="15" Grid.Column="2" Content="{Binding Path=StandardErrorRegex}" />

        <!--StandardInput  -->
        <Label  Grid.Row="16" Grid.Column="0" >StandardInput</Label>
        <ContentControl Grid.Row="16" Grid.Column="2" Content="{Binding Path=StandardInput}" />

        <!--StandardOutputPath  -->
        <Label  Grid.Row="17" Grid.Column="0" >StandardOutputPath</Label>
        <ContentControl Grid.Row="17" Grid.Column="2" Content="{Binding Path=StandardOutputPath}" />

        <!--StandardOutputRegex  -->
        <Label  Grid.Row="18" Grid.Column="0" >StandardOutputRegex</Label>
        <ContentControl Grid.Row="18" Grid.Column="2" Content="{Binding Path=StandardOutputRegex}" />

        <!--TimeoutInSeconds  -->
        <Label  Grid.Row="19" Grid.Column="0" >TimeoutInSeconds</Label>
        <ContentControl Grid.Row="19" Grid.Column="2" Content="{Binding Path=TimeoutInSeconds}" />

        <!--WorkingDirectory  -->
        <Label  Grid.Row="20" Grid.Column="0" >WorkingDirectory</Label>
        <ContentControl Grid.Row="20" Grid.Column="2" Content="{Binding Path=WorkingDirectory}" />


        <!-- Environment Variables -->
        <Label  Grid.Row="21" Grid.Column="0" >Environment Variables</Label>
        <DataGrid  x:Name="EnvironmentVariables" Grid.Row="21" Grid.Column="2" AutoGenerateColumns="False" IsReadOnly="False" CanUserAddRows="False" CanUserDeleteRows="False" ItemsSource="{Binding EnvironmentVariables, ValidatesOnExceptions=True}">
            <DataGrid.RowStyle>
                <Style TargetType="DataGridRow">
                    <Setter Property="ValidationErrorTemplate" Value="{x:Null}"/>
                    <Style.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="BorderBrush" Value="Blue" />
                            <Setter Property="BorderThickness" Value="2" />
                            <Setter Property="Background" Value="LightBlue" />
                            <Setter Property="Foreground" Value="Black" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </DataGrid.RowStyle>
            <DataGrid.CellStyle>
                <Style TargetType="DataGridCell">
                    <Style.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="Background" Value="White" />
                            <Setter Property="Foreground" Value="Black" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </DataGrid.CellStyle>
            <DataGrid.Columns>
                <DataGridTemplateColumn Header="Name" MinWidth="250">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Style="{StaticResource ResourceKey=TextBlockStyle}" Text="{Binding Name.PropertyValue, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <ComboBox x:Name="EnvVariableName" IsEditable="True" 
                                      ItemsSource="{Binding  AvailableParameters}" 
                                      SelectedItem="{Binding Name.SelectedPropertyValue}" 
                                      Text="{Binding Name.PropertyValue, UpdateSourceTrigger=LostFocus, Mode=TwoWay, ValidatesOnDataErrors=True, NotifyOnValidationError=True}"
                                      />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>                  
                </DataGridTemplateColumn>        
                <DataGridTemplateColumn Header="Value" MinWidth="400">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Style="{StaticResource ResourceKey=TextBlockStyle}" Text="{Binding Value.PropertyValue,  ValidatesOnDataErrors=True, NotifyOnValidationError=True}"/>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                    <DataGridTemplateColumn.CellEditingTemplate>
                        <DataTemplate>
                            <ComboBox x:Name="EnvVariableValue" IsEditable="True" 
                                      ItemsSource="{Binding  AvailableParameters}" 
                                      SelectedItem="{Binding Value.SelectedPropertyValue}" 
                                      Text="{Binding Value.PropertyValue, UpdateSourceTrigger=LostFocus, Mode=TwoWay, ValidatesOnDataErrors=True, NotifyOnValidationError=True}"
                                      />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellEditingTemplate>
                </DataGridTemplateColumn>              
            </DataGrid.Columns>
        </DataGrid>
        <ContentPresenter Grid.Row="22" Grid.Column="2" Content="{Binding ElementName=EnvVariableValue, Path=(Validation.Errors).CurrentItem}" />

        <!-- Insert or Delete Rows using button -->
        <StackPanel Orientation = "Horizontal" HorizontalAlignment="Left" Grid.Row="23" Grid.Column="2" >
            <Grid>
                <Grid.RowDefinitions >
                    <RowDefinition Height="6" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="6" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>                   
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="10"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Button Grid.Row="1" Grid.Column="0" Command="{Binding AddEnvironmentVariableCommand}" >
                    <StackPanel Orientation = "Horizontal">
                        <Image  Source="..\Img\addgreen.png" Width="20" Height="20" ></Image>
                        <TextBlock Margin="5,0,0,0">Insert</TextBlock>
                    </StackPanel>
                </Button>
                <Button Grid.Row="1" Grid.Column="2" Command="{Binding DeleteEnvironmentVariableCommand}" CommandParameter="{Binding ElementName=EnvironmentVariables, Path=SelectedItem}">
                    <StackPanel Orientation = "Horizontal">
                        <Image  Source="..\Img\deletered.png" Width="20" Height="20"></Image>
                        <TextBlock Margin="5,0,0,0">Delete</TextBlock>
                    </StackPanel>
                </Button>               
            </Grid>
        </StackPanel>     

    </Grid>  
</UserControl>
